package InternalFrame;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import java.awt.event.*;
import java.awt.*;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;

/* Used by InternalFrameDemo.java. */
public class GradeManager extends JInternalFrame {
    
	static int openFrameCount = 0;
    static final int xOffset = 30, yOffset = 30;
    
	JLabel firstnamel = new JLabel("First Name");
	JTextField firstnamet = new JTextField("First Name");
	
	JLabel lastnamel = new JLabel("Last Name");
	JTextField lastnamet = new JTextField("Last Name");
    
	JLabel addressl = new JLabel("Address");
	JTextField addresst = new JTextField("Address");
	
	JLabel statel = new JLabel("State");
	JTextField statet = new JTextField("State");	
	
	JLabel zipl = new JLabel("Zip");
	JTextField zipt = new JTextField("zip");
	
	JLabel gradel = new JLabel("Grade");
	JTextField gradet = new JTextField("Grade");

	JLabel homephonenumberl = new JLabel("Home Phone Number");
	JTextField homephonenumbert = new JTextField("Home Phone Number");	
	
	JLabel studentphonenumberl = new JLabel("Student Phone Number");
	JTextField studentphonenumbert = new JTextField("StudentPhone Number");
	
	
    JPanel northpanel = new JPanel();
    
    JPanel southpanel = new JPanel();
    
    JButton searchB = new JButton("Search");
    
	JLabel addfirstnamel = new JLabel("First Name");
	JLabel addlastnamel = new JLabel("Last Name");
	JTextField addfirstnamet = new JTextField("Add");
	JTextField addlastnamet = new JTextField();
	JButton addB = new JButton("Add");
	JButton closeB = new JButton("Close");	
    
    
    
    private boolean DEBUG = false;
    private final JLabel lblDateOfBirth = new JLabel("Date of Birth");
    private JTextField txtDateOfBirth;
    private JTextField txtCurrentSchool;
    private final JLabel lblStudentCellNumber = new JLabel("Student Cell Number");
    private final JTextField txtStudentCellNumber = new JTextField();
    private final JLabel lblPrimaryLanguage = new JLabel("Primary Language");
        

    public GradeManager() {
        super("Grade Manager" + (++openFrameCount), 
        	    true, //resizable
                true, //closable
                true, //maximizable
                true);
        txtStudentCellNumber.setText("Student Cell Number");
        txtStudentCellNumber.setBounds(698, 20, 107, 20);
        txtStudentCellNumber.setColumns(10);
        northpanel.setPreferredSize(new Dimension(100,100));
        
        southpanel.setLayout(null);
        southpanel.setPreferredSize(new Dimension(100,100));
		firstnamel.setBounds(5, 0, 80, 20);
		firstnamel.setFont(new Font("arial", Font.PLAIN, 11));
		firstnamet.setBounds(5, 20, 80, 20);
		//firstnamet.setDocument(new JTextFieldLimit(4));
		firstnamet.setToolTipText("Enter the first name");
		lastnamel.setBounds(95, 0, 80, 20);
		lastnamel.setFont(new Font("arial", Font.PLAIN,11));
		lastnamet.setBounds(95, 20, 80, 20);
		lastnamet.setToolTipText("Enter a last name");
		addressl.setBounds(415, 0, 55, 20);
		addressl.setFont(new Font("arial", Font.PLAIN, 11));
		statel.setBounds(480, 0, 44, 20);
		statel.setFont(new Font("arial", Font.PLAIN, 11));
		zipl.setBounds(534, 0, 37, 20);
		zipl.setFont(new Font("arial", Font.PLAIN, 11));
		gradel.setBounds(365, 0, 40, 20);
		gradel.setFont(new Font("arial", Font.PLAIN, 11));
		homephonenumberl.setBounds(581, 0, 107, 20);
		homephonenumberl.setFont(new Font("arial", Font.PLAIN, 11));
		//homephonenumbert.setDocument(new JTextFieldLimit(11));
		
		
		addfirstnamet.setFont(new Font("arial", Font.PLAIN,11));
		addfirstnamet.setBounds(5, 30, 60, 20);
		//addfirstnamet.setDocument(new JTextFieldLimit(4));
		addfirstnamet.setLocation(5, 30);
		
		addlastnamet.setFont(new Font("arial", Font.PLAIN,11));
		addlastnamet.setBounds(147, 30, 67, 20);
		//addlastnamet.setDocument(new JTextFieldLimit(4));
		addlastnamet.setLocation(75, 30);
        searchB.setBounds(0, 80, 80, 20);
        searchB.setToolTipText("Search");
        
        addfirstnamel.setBounds(5, 10, 60, 20);
        addfirstnamel.setFont(new Font("arial", Font.PLAIN,11));
        addfirstnamel.setLocation(5, 10);
        
        addlastnamel.setBounds(147, 10, 67, 20);
        addlastnamel.setFont(new Font("arial", Font.PLAIN,11));
        addlastnamel.setLocation(75, 10);
        
        addB.setBounds(40, 40, 80, 20);
        addB.setLocation(5,60);
        addB.setToolTipText("add");
        
        closeB.setBounds(40, 40, 80, 20);
        closeB.setLocation(285, 60);
        closeB.setToolTipText("Close");
        northpanel.setLayout(null);
        
        
        
        northpanel.add(firstnamel);
        northpanel.add(firstnamet);
        northpanel.add(lastnamel);
        northpanel.add(lastnamet);
        
        northpanel.add(addressl);
        addresst.setBounds(415, 20, 55, 20);
        northpanel.add(addresst);
        northpanel.add(statel);
        statet.setBounds(480, 20, 44, 20);
        northpanel.add(statet);
        northpanel.add(zipl);
        zipt.setBounds(534, 20, 37, 20);
        northpanel.add(zipt);
        northpanel.add(gradel);
        gradet.setBounds(365, 20, 40, 20);
        northpanel.add(gradet);
        northpanel.add(homephonenumberl);
        homephonenumbert.setBounds(581, 20, 107, 20);
        northpanel.add(homephonenumbert);
        northpanel.add(searchB);
        
        
        southpanel.add(addfirstnamel);
        southpanel.add(addlastnamel);
        southpanel.add(addfirstnamet);
        southpanel.add(addlastnamet);
        southpanel.add(addB);
        southpanel.add(closeB);
        
          //...Create the GUI and put it in the window...


          //...Then set the window size or call pack...
          //setSize(1350,670);
        Toolkit toolkit =  Toolkit.getDefaultToolkit ();
        Dimension dim = toolkit.getScreenSize();
        setSize(dim.width,dim.height);

          //Set the window's location.
          //setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
          
          String [] columnNames = {"First Name", "Last Name", "Address", "Grade", "Male"};
          
          Object[][] data = {
          	     {"Kathy", "Smith", "1 Main Street", new Integer(5), new Boolean(false)},
          	      {"John", "Doe", "2 Main Street", new Integer(7), new Boolean(true)},
          	     {"Sue", "Black", "3 Main Street", new Integer(9), new Boolean(false)},
          	      {"Jane", "White", "4 Main Street ", new Integer(6), new Boolean(false)},
          	     {"Joe", "Brown", "5 Main Street", new Integer(4), new Boolean(true)}};

          	        final JTable table = new JTable(data, columnNames);
          	        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
          	        table.setFillsViewportHeight(true);

          	        if (DEBUG) {
          	             table.addMouseListener(new MouseAdapter() {
          	                public void mouseClicked(MouseEvent e) {
          	                    printDebugData(table);
          	                }
          	            });
          	        }

          	        //Create the scroll pane and add the table to it.
          	        JScrollPane scrollPane = new JScrollPane(table);
          	        
          	      closeB.addActionListener(new ActionListener() {
      				
      				public void actionPerformed(ActionEvent ae) {
      					
      					dispose();
      				}
      				
      			});

          	        //Add the scroll pane to this panel.
          	        getContentPane().add(northpanel,BorderLayout.NORTH);
          	        lblDateOfBirth.setBounds(185, 3, 74, 14);
          	        
          	        northpanel.add(lblDateOfBirth);
          	        
          	        txtDateOfBirth = new JTextField();
          	        txtDateOfBirth.setText("Date of Birth");
          	        txtDateOfBirth.setBounds(185, 20, 74, 20);
          	        northpanel.add(txtDateOfBirth);
          	        txtDateOfBirth.setColumns(10);
          	        
          	        JLabel lblCurrentSchool = new JLabel("Current School");
          	        lblCurrentSchool.setBounds(269, 3, 86, 14);
          	        northpanel.add(lblCurrentSchool);
          	        
          	        txtCurrentSchool = new JTextField();
          	        txtCurrentSchool.setText("Current School");
          	        txtCurrentSchool.setBounds(269, 20, 86, 20);
          	        northpanel.add(txtCurrentSchool);
          	        txtCurrentSchool.setColumns(10);
          	        lblStudentCellNumber.setBounds(698, 3, 107, 14);
          	        
          	        northpanel.add(lblStudentCellNumber);
          	        
          	        northpanel.add(txtStudentCellNumber);
          	        lblPrimaryLanguage.setBounds(815, 3, 96, 14);
          	        
          	        northpanel.add(lblPrimaryLanguage);
          	        
          	        JComboBox comboBox = new JComboBox();
          	        comboBox.setBounds(815, 20, 96, 20);
          	        northpanel.add(comboBox);
          	        
          	        JRadioButton rdbtnMale = new JRadioButton("Male");
          	        rdbtnMale.setBounds(917, -1, 109, 23);
          	        northpanel.add(rdbtnMale);
          	        
          	        JRadioButton rdbtnFemale = new JRadioButton("Female");
          	        rdbtnFemale.setBounds(917, 19, 109, 23);
          	        northpanel.add(rdbtnFemale);
          	        
          	        JCheckBox chckbxIep = new JCheckBox("IEP");
          	        chckbxIep.setBounds(5, 47, 97, 23);
          	        northpanel.add(chckbxIep);
          	        getContentPane().add(scrollPane, BorderLayout.CENTER);
          	        getContentPane().add(southpanel,BorderLayout.SOUTH);
          	        
          	    }

          	    private void printDebugData(JTable table) {
          	        int numRows = table.getRowCount();
          	        int numCols = table.getColumnCount();
          	        javax.swing.table.TableModel model = table.getModel();

          	        System.out.println("Value of data: ");
          	        for (int i=0; i < numRows; i++) {
          	            System.out.print("    row " + i + ":");
          	            for (int j=0; j < numCols; j++) {
          	                 System.out.print("  " + model.getValueAt(i, j));
          	            }
          	            System.out.println();
          	        }
          	        System.out.println("--------------------------");
          	     }
      }